package com.kizuki.rpc;

import com.kizuki.rpc.service.UserService;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

public class TestClient {

    private void startClient(String userName) {
        TTransport transport = null;
        try {
            transport = new TSocket("localhost", TestServer.PORT);
            // 协议要和服务端一致
            TProtocol protocol = new TBinaryProtocol(transport);
            UserService.Client client = new UserService.Client(protocol);
            transport.open();
            System.out.println("client.getName = 1 : " + client.getName(1));
            System.out.println("client.isExist = MADAO : " + client.isExist("MADAO"));
        } catch (TException e) {
            e.printStackTrace();
        } finally {
            if (transport != null) {
                transport.close();
            }
        }
    }

    public static void main(String[] args) {
        TestClient client = new TestClient();
        client.startClient("Tom");
    }

}